USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Countries-Insert]    Script Date: [[20120914064950]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064950]]
-- Description:	Insert record into table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Insert]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null  , 
	@Country_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Countries](/*[Country_ID], [Country_Code], [Country_NameAr], [Country_NameEn], [Country_Notes], [Country_Search]*/)
	VALUES     (/*@Country_ID, @Country_Code, @Country_NameAr, @Country_NameEn, @Country_Notes, @Country_Search*/)

	/*SELECT @Country_RowNumber = [Country_RowNumber], @Country_TimeStamp = [Country_TimeStamp]
    FROM [dbo].[Countries]
    WHERE  ( [Country_ID] =@Country_ID )
	AND  ( [Country_Code] =@Country_Code )
	AND  ( [Country_NameAr] =@Country_NameAr )
	AND  ( [Country_NameEn] =@Country_NameEn )
	AND  ( [Country_Notes] =@Country_Notes )
	AND  ( [Country_Search] =@Country_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Countries-update]    Script Date: [[20120914064950]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064950]]
-- Description:	Update record in table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-update]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null  , 
	@Country_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Country_TimeStamp]
    FROM [dbo].[Countries]
    	WHERE ([Country_ID] = @Country_ID)

    IF  @OldTimeStamp = @Country_TimeStamp
    BEGIN*/
		Update [dbo].[Countries] SET 
		/*[Country_ID] =@Country_ID, 
		[Country_Code] =@Country_Code, 
		[Country_NameAr] =@Country_NameAr, 
		[Country_NameEn] =@Country_NameEn, 
		[Country_Notes] =@Country_Notes, 
		[Country_Search] =@Country_Search*/
		/*WHERE ([Country_ID] = @Country_ID)*/
	/*END*/

	/*SELECT @Country_RowNumber = [Country_RowNumber], @Country_TimeStamp = [Country_TimeStamp]
    FROM [dbo].[Countries]
	WHERE ([Country_ID] = @Country_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Countries-Insert-Update]    Script Date: [[20120914064950]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064950]]
-- Description:	Insert OR Update record into table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Insert-Update]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null  , 
	@Country_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Countries] 
					/*WHERE ([Country_ID] = @Country_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Countries](/*[Country_ID], [Country_Code], [Country_NameAr], [Country_NameEn], [Country_Notes], [Country_Search]*/)
		VALUES     (/*@Country_ID, @Country_Code, @Country_NameAr, @Country_NameEn, @Country_Notes, @Country_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Country_TimeStamp]
		FROM [dbo].[Countries]
    	WHERE ([Country_ID] = @Country_ID)

		IF  @OldTimeStamp = @Country_TimeStamp
		BEGIN*/
			Update [dbo].[Countries] SET 
			/*[Country_ID] =@Country_ID, 
			[Country_Code] =@Country_Code, 
			[Country_NameAr] =@Country_NameAr, 
			[Country_NameEn] =@Country_NameEn, 
			[Country_Notes] =@Country_Notes, 
			[Country_Search] =@Country_Search*/
			/*WHERE ([Country_ID] = @Country_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Country_RowNumber = [Country_RowNumber], @Country_TimeStamp = [Country_TimeStamp]
    FROM [dbo].[Countries]
	WHERE ([Country_ID] = @Country_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Countries-Delete]    Script Date: [[20120914064950]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064950]]
-- Description:	delete records from table [dbo].[Countries] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Delete]
	/*@Country_RowNumber int =null  , 
	@Country_ID uniqueidentifier =null  , 
	@Country_Code varchar(50) =null  , 
	@Country_NameAr varchar(300) =null  , 
	@Country_NameEn varchar(300) =null  , 
	@Country_Notes varchar(max) =null  , 
	@Country_Search varchar(max) =null  , 
	@Country_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Countries]
	WHERE /*( [Country_RowNumber] = ISNULL(@Country_RowNumber, [Country_RowNumber]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [Country_Code] like ISNULL(@Country_Code, [Country_Code]) )
	AND ( [Country_NameAr] like ISNULL(@Country_NameAr, [Country_NameAr]) )
	AND ( [Country_NameEn] like ISNULL(@Country_NameEn, [Country_NameEn]) )
	AND ( [Country_Notes] like ISNULL(@Country_Notes, [Country_Notes]) )
	AND ( [Country_Search] like ISNULL(@Country_Search, [Country_Search]) )
	AND ( [Country_TimeStamp] = ISNULL(@Country_TimeStamp, [Country_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Countries-Select]    Script Date: [[20120914064950]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064950]]
-- Description:	select records from table [dbo].[Countries] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Select]
	/*@Country_RowNumber int =null  , 
	@Country_ID uniqueidentifier =null  , 
	@Country_Code varchar(50) =null  , 
	@Country_NameAr varchar(300) =null  , 
	@Country_NameEn varchar(300) =null  , 
	@Country_Notes varchar(max) =null  , 
	@Country_Search varchar(max) =null  , 
	@Country_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Countries]
	WHERE /*( [Country_RowNumber] = ISNULL(@Country_RowNumber, [Country_RowNumber]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [Country_Code] like ISNULL(@Country_Code, [Country_Code]) )
	AND ( [Country_NameAr] like ISNULL(@Country_NameAr, [Country_NameAr]) )
	AND ( [Country_NameEn] like ISNULL(@Country_NameEn, [Country_NameEn]) )
	AND ( [Country_Notes] like ISNULL(@Country_Notes, [Country_Notes]) )
	AND ( [Country_Search] like ISNULL(@Country_Search, [Country_Search]) )
	AND ( [Country_TimeStamp] = ISNULL(@Country_TimeStamp, [Country_TimeStamp]) )*/
END
GO
-- =============================================
